package graduate.wangyaqi.ErrorCorrectionQuestions;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.swing.text.html.Option;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class ErrorCorrectionQuestionsService {
    @Resource
    private ErrorCorrectionQuestionsRepository errorCorrectionQuestionsRepository;

    //保存数据
    @Transactional
    public void save(ErrorCorrectionQuestions errorCorrectionQuestion) {
        errorCorrectionQuestionsRepository.save(errorCorrectionQuestion);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        errorCorrectionQuestionsRepository.deleteById(id);
    }

    @Transactional
    public void deleteAll(){
        errorCorrectionQuestionsRepository.deleteAll();
    }

    //查询数据
    @Transactional
    public Iterable<ErrorCorrectionQuestions> getAll() {
        Iterable<ErrorCorrectionQuestions> errorCorrectionQuestions = errorCorrectionQuestionsRepository.findAll();
        return errorCorrectionQuestions;
    }

    @Transactional
    public Iterable<ErrorCorrectionQuestions> getAllByTaotiID(Long id){
        Iterable<ErrorCorrectionQuestions> list = errorCorrectionQuestionsRepository.findAllByTaotiID(id);
        return list;
    }

    @Transactional
    public Optional<ErrorCorrectionQuestions> findById(Long aLong){
        Optional<ErrorCorrectionQuestions> item= errorCorrectionQuestionsRepository.findById(aLong);
        return errorCorrectionQuestionsRepository.findById(aLong);
    };

    @Transactional
    public int countAllByStuIDadnAndTaotiID(Long taotaoId ){
        return errorCorrectionQuestionsRepository.countAllByTaotiID(taotaoId);
    }

    @Transactional
    public ErrorCorrectionQuestions getFirstByTaotiIDAndIdIsGreaterThan(long taotiId, long id){
        return errorCorrectionQuestionsRepository.getFirstByTaotiIDAndIdGreaterThan(taotiId,id);
    }

    @Transactional
    public ErrorCorrectionQuestions getFirstByTaotiIDAndIdLessThan(long taotiId, long id){
        return errorCorrectionQuestionsRepository.getFirstByTaotiIDAndIdLessThanOrderByIdDesc(taotiId,id);
    }
}
